// TestSubTitle2.cpp : implementation file
//

#include "stdafx.h"
#include "MultiMedia.h"
#include "TestSubTitle2.h"
#include <string>


// TestSubTitle2 dialog

IMPLEMENT_DYNCREATE(TestSubTitle2, CDHtmlDialog)

TestSubTitle2::TestSubTitle2(CWnd* pParent /*=NULL*/)
	: CDHtmlDialog(TestSubTitle2::IDD, TestSubTitle2::IDH, pParent)
{

}

TestSubTitle2::~TestSubTitle2()
{
}

void TestSubTitle2::DoDataExchange(CDataExchange* pDX)
{
	CDHtmlDialog::DoDataExchange(pDX);
}

BOOL TestSubTitle2::OnInitDialog()
{
	CDHtmlDialog::OnInitDialog();

	SetWindowLong(this->m_hWnd, GWL_EXSTYLE, GetWindowLong(this->m_hWnd,GWL_EXSTYLE) ^ WS_EX_LAYERED);
	SetLayeredWindowAttributes(RGB(255, 0, 0), 0, LWA_COLORKEY);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

BEGIN_MESSAGE_MAP(TestSubTitle2, CDHtmlDialog)
END_MESSAGE_MAP()

bool TestSubTitle2::SetTextCaption(BSTR caption, bool isBold)
{
CRect rc;
	this->GetClientRect(&rc);
	
	char setFontsize[33];
	itoa (rc.Height()/6, setFontsize, 10);

	std::string cap = _bstr_t(caption);

	std::string addFontsize;

	if (isBold)
	{	
		addFontsize.append("<b style = 'font-size:");
	}
	else
	{
		addFontsize.append("<span style = 'font-size:");
		
	}

	addFontsize.append(setFontsize);
	addFontsize.append("pt;'>");

	int pos = cap.find(">");
	if (pos > 0) 	
		cap.insert(pos + 1, addFontsize);

	caption =   A2BSTR(cap.c_str());

	IHTMLElement* pLinkElement = NULL;

	if (GetElement(_T("caption"), &pLinkElement) == S_OK && pLinkElement != NULL)
	{
		
		 pLinkElement->put_innerHTML(caption);
		 pLinkElement->Release();
		 return true;
	}

	return false;

}

